<!DOCTYPE html>
<html lang="zh-CN,zh-Hans,default">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"51liveup.cn","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="首先基于centos7的镜像安装Oracle-java">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker_使用Dockerfile创建Tomcat">
<meta property="og:url" content="http://51liveup.cn/2016/05/27/Docker_%E4%BD%BF%E7%94%A8Dockerfile%E5%88%9B%E5%BB%BATomcat/index.html">
<meta property="og:site_name" content="快乐地生活">
<meta property="og:description" content="首先基于centos7的镜像安装Oracle-java">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2016-05-27T07:10:42.000Z">
<meta property="article:modified_time" content="2021-09-04T02:41:42.460Z">
<meta property="article:author" content="大道自然">
<meta property="article:tag" content="docker">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://51liveup.cn/2016/05/27/Docker_%E4%BD%BF%E7%94%A8Dockerfile%E5%88%9B%E5%BB%BATomcat/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Docker_使用Dockerfile创建Tomcat | 快乐地生活</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">快乐地生活</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://51liveup.cn/2016/05/27/Docker_%E4%BD%BF%E7%94%A8Dockerfile%E5%88%9B%E5%BB%BATomcat/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="大道自然">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="快乐地生活">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Docker_使用Dockerfile创建Tomcat
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2016-05-27 15:10:42" itemprop="dateCreated datePublished" datetime="2016-05-27T15:10:42+08:00">2016-05-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-09-04 10:41:42" itemprop="dateModified" datetime="2021-09-04T10:41:42+08:00">2021-09-04</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%8A%80%E6%9C%AF/" itemprop="url" rel="index"><span itemprop="name">技术</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%8A%80%E6%9C%AF/docker/" itemprop="url" rel="index"><span itemprop="name">docker</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>首先基于centos7的镜像安装Oracle-java</p>
<span id="more"></span>
<p>Dockerfile的内容如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">FROM centos:7</span><br><span class="line"></span><br><span class="line">MAINTAINER oneyi &lt;master@51liveup.cn&gt;</span><br><span class="line"></span><br><span class="line">RUN yum update -y &amp;&amp; \</span><br><span class="line">yum install -y wget &amp;&amp; \</span><br><span class="line">wget --no-cookies --no-check-certificate --header &quot;Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie&quot; &quot;http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.rpm&quot; &amp;&amp; \</span><br><span class="line">yum localinstall -y jdk-8u65-linux-x64.rpm &amp;&amp; \</span><br><span class="line">rm -f jdk-8u65-linux-x64.rpm &amp;&amp; \</span><br><span class="line">yum clean all</span><br><span class="line"></span><br><span class="line"># Set environment variables.</span><br><span class="line">ENV HOME /root</span><br><span class="line"></span><br><span class="line"># Define working directory.</span><br><span class="line">WORKDIR /root</span><br><span class="line"></span><br><span class="line"># Define default command.</span><br><span class="line">CMD [&quot;bash&quot;]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>使用build进行编译</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker build -t java:8 - &lt; Dockerfile</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>再基于刚才构建的java环境安装tomcat</p>
<p>Dockerfile的内容如下（和刚才的Dockerfile不是一个文件哦）</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">FROM java:oneyi</span><br><span class="line"></span><br><span class="line">MAINTAINER oneyi &lt;master@51liveup.cn&gt;</span><br><span class="line"></span><br><span class="line">ENV CATALINA_HOME /usr/local/tomcat</span><br><span class="line">ENV PATH $CATALINA_HOME/bin:$PATH</span><br><span class="line">RUN mkdir -p &quot;$CATALINA_HOME&quot;</span><br><span class="line">WORKDIR $CATALINA_HOME</span><br><span class="line"></span><br><span class="line"># see https://www.apache.org/dist/tomcat/tomcat-8/KEYS</span><br><span class="line">RUN set -ex \</span><br><span class="line">	&amp;&amp; for key in \</span><br><span class="line">		05AB33110949707C93A279E3D3EFE6B686867BA6 \</span><br><span class="line">		07E48665A34DCAFAE522E5E6266191C37C037D42 \</span><br><span class="line">		47309207D818FFD8DCD3F83F1931D684307A10A5 \</span><br><span class="line">		541FBE7D8F78B25E055DDEE13C370389288584E7 \</span><br><span class="line">		61B832AC2F1C5A90F0F9B00A1C506407564C17A3 \</span><br><span class="line">		79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED \</span><br><span class="line">		9BA44C2621385CB966EBA586F72C284D731FABEE \</span><br><span class="line">		A27677289986DB50844682F8ACB77FC2E86E29AC \</span><br><span class="line">		A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 \</span><br><span class="line">		DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 \</span><br><span class="line">		F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE \</span><br><span class="line">		F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23 \</span><br><span class="line">	; do \</span><br><span class="line">		gpg --keyserver ha.pool.sks-keyservers.net --recv-keys &quot;$key&quot;; \</span><br><span class="line">	done</span><br><span class="line">	</span><br><span class="line">ENV TOMCAT_MAJOR 8</span><br><span class="line">ENV TOMCAT_VERSION 8.5.2</span><br><span class="line">ENV TOMCAT_TGZ_URL https://www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz</span><br><span class="line"></span><br><span class="line">RUN set -x \</span><br><span class="line">	\</span><br><span class="line">	&amp;&amp; curl -fSL &quot;$TOMCAT_TGZ_URL&quot; -o tomcat.tar.gz \</span><br><span class="line">	&amp;&amp; curl -fSL &quot;$TOMCAT_TGZ_URL.asc&quot; -o tomcat.tar.gz.asc \</span><br><span class="line">	&amp;&amp; gpg --batch --verify tomcat.tar.gz.asc tomcat.tar.gz \</span><br><span class="line">	&amp;&amp; tar -xvf tomcat.tar.gz --strip-components=1 \</span><br><span class="line">	&amp;&amp; rm bin/*.bat \</span><br><span class="line">	&amp;&amp; rm tomcat.tar.gz* </span><br><span class="line"></span><br><span class="line">EXPOSE 8080</span><br><span class="line">CMD [&quot;catalina.sh&quot;, &quot;run&quot;]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>使用build进行编译</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker build -t tomcat:8.5 - &lt; Dockerfile</span><br><span class="line"></span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/docker/" rel="tag"># docker</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2016/05/26/Docker%E4%BD%BF%E7%94%A8%E8%BF%87%E7%A8%8B/" rel="prev" title="docker使用过程记录_nginx">
      <i class="fa fa-chevron-left"></i> docker使用过程记录_nginx
    </a></div>
      <div class="post-nav-item">
    <a href="/2016/05/30/Docker_%E6%9D%82%E8%AE%B0/" rel="next" title="Docker_使用杂记">
      Docker_使用杂记 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">大道自然</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">30</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">大道自然</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
